package aufgaben170311;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class SakilaTestA {

	public static void main(String[] args) {
		try {
			// DB Verbindung
			Class.forName("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection
				("jdbc:mysql://localhost/sakila?user=root&password=");
			
			// Tastatureingabe
			Scanner sc = new Scanner(System.in);
		    System.out.print("Gib was ein: ");
		    String eingabe = sc.next();
		    
		    // DB Abfrage
			CallableStatement cst = conn.prepareCall("{call findTitles(?)}");
			
			cst.setString(1, eingabe);
			boolean resultType = cst.execute();
			ResultSet rs = null;
			if(resultType)
			{
				rs = cst.getResultSet();
				while(rs.next()) {
					System.out.println(rs.getInt(1)+" - "+rs.getString(2)+" - "+rs.getString(3)+" - "+rs.getInt(4));
				}
			}
			
			conn.close();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
